package com.testing.class4;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

/**
 * @Classname RobotTest
 * @Description 类型说明
 * @Date 2022/10/12 21:18
 * @Created by 特斯汀Roy
 */
public class RobotTest {
    public static void main(String[] args) throws AWTException, InterruptedException {

        //核心api是 操作鼠标移动  操作鼠标点击   键盘输入。

        Robot robot=new Robot();
        Thread.sleep(2000);
        robot.mouseMove(1190,610);
        robot.mousePress(KeyEvent.BUTTON1_MASK);
        robot.mouseRelease(KeyEvent.BUTTON1_MASK);
//        robot.keyPress(KeyEvent.VK_R);
//        robot.keyRelease(KeyEvent.VK_R);
//        robot.keyPress(KeyEvent.VK_O);
//        robot.keyRelease(KeyEvent.VK_O);
//        robot.keyPress(KeyEvent.VK_Y);
//        robot.keyRelease(KeyEvent.VK_Y);

//        String s="or";
//        char[] chars = s.toCharArray();
//        for (char aChar : chars) {
//            switch (aChar){
//                case 'r':
//                    robot.keyPress(KeyEvent.VK_R);
//                    robot.keyRelease(KeyEvent.VK_R);
//                    break;
//                case 'o':
//                    robot.keyPress(KeyEvent.VK_O);
//                    robot.keyRelease(KeyEvent.VK_O);
//                    break;
//            }
//        }

        String s="E:\\QSwork\\素材\\悠米微信 .png";
        //开启一个剪贴板
        Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
        //剪贴的内容
        StringSelection content=new StringSelection(s);
        clipboard.setContents(content,null);
        //Robot实现粘贴
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);
        robot.delay(2000);
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);

    }

}